package com.zdb.order.controller;


import com.zdb.order.entity.OrderMaster;
import com.zdb.order.service.OrderMasterService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderMasterController {
    @Autowired
    private OrderMasterService orderMasterService;
    @GetMapping("listOrder")
    public List<OrderMaster> getListOrders(
            @RequestParam(name = "uid") String uid,
            @RequestParam(name = "orderType") String orderType
    ){
        System.out.println("uid:"+uid);
        List<OrderMaster> resultList = orderMasterService.getListOrders(uid,orderType);
        return resultList;
    }

    @GetMapping("listOrderByRiders")
    public List<OrderMaster> getListOrdersByRiders(
            @RequestParam(name = "rid") String rid,
            @RequestParam(name = "orderType") String orderType
    ){
        System.out.println("rid:"+rid);
        List<OrderMaster> resultList = orderMasterService.getListOrdersByRiders(rid,orderType);
        return resultList;
    }

    @GetMapping("clickOrder")
    public ResponseEntity<Void> getClickOrder(
            @RequestParam(name = "rid") String rid,
            @RequestParam(name = "orderId") String orderId
    ){
        System.out.println("rid:"+rid);
        System.out.println("orderId:"+orderId);

        int resultCount = orderMasterService.getClickOrder(rid,orderId);
        if(resultCount!=0){
            return new ResponseEntity<>(HttpStatus.OK);
        }

        return ResponseEntity.ok(null);
    }
}
